package com.telenav.techtalk;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;

public class AndroidGraphicsActivity extends ListActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent matrixIntent = new Intent();
        matrixIntent.addCategory(Intent.CATEGORY_DEFAULT);
        matrixIntent.setClass(this, MatrixActivity.class);
        
        Intent colorMatrixIntent = new Intent();
        colorMatrixIntent.addCategory(Intent.CATEGORY_DEFAULT);
        colorMatrixIntent.setClass(this, ColorMatrixActivity.class);
        
        Intent shaderRoundRect = new Intent();
        shaderRoundRect.addCategory(Intent.CATEGORY_DEFAULT);
        shaderRoundRect.setClass(this, ShaderRoundRectActivity.class);
        
        Intent gifIntent = new Intent();
        gifIntent.addCategory(Intent.CATEGORY_DEFAULT);
        gifIntent.setClass(this, GifActivity.class);
        
        Intent alphaView = new Intent();
        alphaView.addCategory(Intent.CATEGORY_DEFAULT);
        alphaView.setClass(this, AlphaViewGroupActivity.class);
        
        Intent clipView = new Intent();
        clipView.addCategory(Intent.CATEGORY_DEFAULT);
        clipView.setClass(this, ClipActivity.class);
        
        Intent effectView = new Intent();
        effectView.addCategory(Intent.CATEGORY_DEFAULT);
        effectView.setClass(this, PathEffectActivity.class);
        
        Intent verticeIntent = new Intent();
        verticeIntent.addCategory(Intent.CATEGORY_DEFAULT);
        verticeIntent.setClass(this, VerticesActivity.class);
        Intent[] its = new Intent[]{
        		matrixIntent,
        		clipView,
        		alphaView,
        		colorMatrixIntent,
        		effectView,
        		shaderRoundRect,
        		verticeIntent,
        		gifIntent
        		};
        setListAdapter(new IntentListAdapter<Intent>(this, its));
    }
    
    class IntentListAdapter<T extends Intent> extends ArrayAdapter<T>
    {

        /**
         * @param context
         * @param textViewResourceId
         * @param objects
         */
        public IntentListAdapter(Context context, T[] objects) {
            super(context, -1, objects);
        }
        
        public View getView(int position, View convertView, ViewGroup parent) {
            Button btn = new Button(AndroidGraphicsActivity.this);
            final T item = getItem(position);
            btn.setText(item.getComponent().getShortClassName());
            btn.setOnClickListener(new View.OnClickListener() {
                
                public void onClick(View v) {
                    getContext().startActivity(item);
                }
            });
            return btn;
            
        }
        
    }
}